let cartinfo = document.querySelector('.cartinfo')
let shopArr = JSON.parse(localStorage.getItem('shopArr'))
fnew()
function fnew() {
  let ncount = 0
  let price = 0
  cartinfo.innerHTML = ''
  if(shopArr.length!=0){
    shopArr.forEach(function (ele) {
      cartinfo.innerHTML += `
      <div class="cartitm">
              <div class="cartimg"><img src="${ele.goods_small_logo}" alt=""></div>
              <div class="spinfo">
                <p class="title">
                <a href="../html/details.html?id=${ele.goods_id}" target="_blank">${ele.goods_name}</a>
                </p>
                <p>销售价：<span>￥${parseInt(ele.goods_price).toFixed(2)}</span></p>
                <div>
                  <p>数量：<span>${ele.count}</span></p>
                  <a href="javascript:;" class="movesp" data-id="${ele.goods_id}">移除</a>
                </div>
              </div>
            </div>
      `
      ncount+=ele.count
      price += ele.count * ele.goods_price
      cartinfo.innerHTML += `
      <div class="cartpric">
        <p>共 ${ncount}件商品</p>
        <p>商品总金额<span>￥ ${price}</span></p>
        <p>订单优惠金额<span>￥0.0</span></p>
        <p>金额总计<span>￥${price}</span></p>
        <a href="../html/car.html" class="jiesuan">去结算</a>
      </div>
        `
    })
  }else{
    cartinfo.innerHTML+=`购物车中还没有商品赶紧选购吧`

    // nosp.style.display = 'block'
  }

 

  localStorage.setItem('shopArr', JSON.stringify(shopArr))

}

cartinfo.addEventListener('click', function (e) {
  e = e || window.event
  var target = e.target || e.srcElement
  if (target.className == 'movesp') {
    let id = target.getAttribute('data-id')
    for (let i = 0; i < shopArr.length; i++) {
      if (shopArr[i].goods_id == id) {
        shopArr.splice(i, 1)
          i--
      }
  }
  fnew()
  }
})